<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        html {
            height: 100%;
        }
        body {
            height: 100%;
        }
        .container {
            height: 100%;
            background-image: linear-gradient(to right, #fbc2eb, #a6c1ee);
        }
        .login-wrapper {
            background-color: #fff;
            width: 358px;
            height: 588px;
            border-radius: 15px;
            padding: 0 50px;
            position: relative;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }
        .header {
            font-size: 38px;
            font-weight: bold;
            text-align: center;
            line-height: 200px;
        }
        .input-item {
            display: block;
            width: 100%;
            margin-bottom: 20px;
            border: 0;
            padding: 10px;
            border-bottom: 1px solid rgb(128, 125, 125);
            font-size: 15px;
            outline: none;
        }
        .input-item:placeholder {
            text-transform: uppercase;
        }
        .btn {
            text-align: center;
            padding: 10px;
            width: 100%;
            margin-top: 40px;
            background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
            color: #fff;
        }
        .msg {
            text-align: center;
            line-height: 88px;
        }
        a {
            text-decoration-line: none;
            color: #abc1ee;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="login-wrapper">
            <div class="header">Login</div>
            <div class="form-wrapper">
                <input type="text" name="username" placeholder="username" class="input-item">
                <input type="password" name="password" placeholder="password" class="input-item">
                <div class="btn">Login</div>
            </div>
            <div class="msg">
                Don't have account?
                <a href="#">Sign up</a>
            </div>
        </div>
    </div>
</body>

<script>
  let res = []
  let reply_comment = []
  let reply_list = []
  let list = [
    {
        "content": "你好啊",
        "id": 1,
        "blog_id": 14,
        "user_id": 2,
        "created_at": "2023-07-28T11:22:10",
        "reply": [
            {
                "reply_type": "0",
                "content": "你也好",
                "reply_id": 1,
                "commetn_id": 1,
                "user_id": 1,
                "id": 1,
                "created_at": "2023-07-28T11:25:23"
            },
            {
                "reply_type": "1",
                "content": "你想说啥",
                "reply_id": 1,
                "commetn_id": 1,
                "user_id": 2,
                "id": 2,
                "created_at": "2023-07-28T11:35:21"
            },
            {
                "reply_type": "1",
                "content": "你们在说啥",
                "reply_id": 1,
                "commetn_id": 1,
                "user_id": 3,
                "id": 3,
                "created_at": "2023-07-28T11:39:51"
            },
            {
                "reply_type": "0",
                "content": "别他妈说你好咯",
                "reply_id": 1,
                "commetn_id": 1,
                "user_id": 3,
                "id": 4,
                "created_at": "2023-07-28T11:46:01"
            },
            {
                "reply_type": "1",
                "content": "测试对不对",
                "reply_id": 2,
                "commetn_id": 1,
                "user_id": 1,
                "id": 6,
                "created_at": "2023-07-28T14:23:55"
            },
            {
                "reply_type": "1",
                "content": "多次测试对不对",
                "reply_id": 2,
                "commetn_id": 1,
                "user_id": 1,
                "id": 7,
                "created_at": "2023-07-28T14:26:48"
            },
            {
                "reply_type": "1",
                "content": "看看",
                "reply_id": 7,
                "commetn_id": 1,
                "user_id": 1,
                "id": 8,
                "created_at": "2023-07-28T14:27:55"
            },
            {
                "reply_type": "1",
                "content": "再看一看",
                "reply_id": 3,
                "commetn_id": 1,
                "user_id": 1,
                "id": 9,
                "created_at": "2023-07-28T14:28:49"
            }
        ]
    },
    {
        "content": "八嘎有",
        "id": 2,
        "blog_id": 14,
        "user_id": 3,
        "created_at": "2023-07-28T11:46:26",
        "reply": [
            {
                "reply_type": "0",
                "content": "太君大大地",
                "reply_id": 1,
                "commetn_id": 2,
                "user_id": 1,
                "id": 5,
                "created_at": "2023-07-28T11:51:16"
            }
        ]
    }
]



  list.forEach(it => {
    let newIt = JSON.parse(JSON.stringify(it))
    newIt.reply = []
    res.push(newIt)

    it.reply?.forEach(item => {
      item.reply = []
      if (item.reply_type == '0') reply_comment.push(item)
      if (item.reply_type == '1') reply_list.push(item)
    })
  })

  let handelComment = () => {
    // console.log(reply_list, reply_comment)
    // 处理所有回复评论的数据
    reply_comment.forEach(it => {
      res.forEach(item => {
        if (it.commetn_id == item.id){
          it.reply = []
          item.reply.push(it)
        }
      })
    })

    // 重头戏！ 处理所有回复回复的数据
    handelreply(res)
  }

  let handelreply = (it) => {
    it.forEach(item => {
      if (item.reply.length > 0) {
        handelreply(item.reply)
        return
      }

      reply_list.forEach(i => {
        if (i.reply_type == '1' && item.id == i.reply_id) {
          item.reply.push(i)
          handelreply(res)
        }
      })
    })
  }

  handelComment()
  console.log(res);

</script>
</html>
